package com.example.response;

import com.example.constant.ResultCodeConstant;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * <p>
 * 统一响应类
 * </p>
 * @author 34448
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class RestResult<T> implements Serializable {

    /**
     * 业务返回码
     */
    @ApiModelProperty(value = "业务返回码")
    private String code;

    /**
     * 业务提示信息
     */
    @ApiModelProperty(value = "业务提示信息")
    private String msg;

    /**
     * 业务数据
     */
    @ApiModelProperty(value = "业务数据")
    private T data;

    public RestResult(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public RestResult(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> RestResult<T> success(T data) {
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, data);
    }

    public static RestResult<Void> failure(String code, String msg) {
        return new RestResult<>(code, msg);
    }
}